<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    var Person; //暴露入口
    (function () {
      var instance;
      Person = function Person() {
        if (instance) {
          return instance;
        }
        instance = this;
        this.name = "xx";
        this.eat = function () {
          console.log(this.name + "是个吃货！");
        };
      };
    })();

    var p1 = new Person();
    console.log(p1);
    Person.prototype.sex = "男";
    var p2 = new Person();//这里的p2和p1是完全一样的，所以没必要再实例化
    console.log(p1.sex, p2.sex);
    console.log(p1.constructor === Person); //true 说明P1是Person的实例
  </script>
</html>
